package schoolWork.work05.Example5b;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//用匿名类实现
public class PoliceWindow extends JFrame {
    JTextField titleText;
    JPasswordField passwordText;

    PoliceWindow() {
        titleText = new JTextField(10);
        passwordText = new JPasswordField(10);

        passwordText.setEchoChar('*');
        titleText.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setTitle(titleText.getText());
            }
        });
        passwordText.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                char c[] = passwordText.getPassword();
                titleText.setText(new String(c));
            }
        });
        setLayout(new FlowLayout());
        add(titleText);
        add(passwordText);

        setBounds(100, 100, 150, 150);
        setVisible(true);
        validate();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}